﻿<!DOCTYPE html>
<html>

<head id="Head1" runat="server">
  <title>工时统计查询</title>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <link rel="stylesheet" href="../StaticFiles/layui/dist/css/layui.css" />
  <link rel="stylesheet" href="../styles/reportpage.css" />
  <script type="text/javascript" src="../Scripts/json2.js"></script>
  <script type="text/javascript" src="../Scripts/jquery-1.11.2.min.js"></script>
  <script type="text/javascript" src="../Scripts/jquery.fileDownload.js"></script>
</head>

<body>
  <!--[if lt IE 9]>
        <script src="../Scripts/pollyfills/html5.js"></script>
        <script src="../Scripts/pollyfills/response.js"></script>
        <script src="../Scripts/pollyfills/array.pollyfill.js"></script>
    <![endif]-->
  <!-- 页眉区域 start-->
  <div class="layui-row layui-bg-green" style="padding: 0 15px; margin-bottom: 5px;">
    <div class="layui-col-md3">
      <div>
        <img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" />
      </div>
    </div>
    <div class="layui-col-md6 header-title">
      装配试车厂工时统计报表
    </div>
    <div class="layui-col-md3" style="height: 60px; line-height: 60px; text-align: right;
            font-size: 16px; font-weight: bold; color: #fff; padding-right: 15px;" id="currentTime">
    </div>
  </div>
  <form class="layui-form" action="">
    <!--第一行-->
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 所属分厂：
        </label>
        <div class="layui-input-inline" lay-filter="ddlFactory">
          <select name="ddlFactory" lay-verify="required" id="ddlFactory" lay-filter="ddlFactory">
            <option value=""></option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 所属工区：
        </label>
        <div class="layui-input-inline">
          <select name="ddlWorkcenter" lay-verify="required" lay-search="" id="ddlWorkcenter"
            lay-filter="ddlWorkcenter">
            <option value=""></option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 班：
        </label>
        <div class="layui-input-inline">
          <select name="ddlShift" lay-verify="required" lay-search="" id="ddlShift" lay-filter="ddlShift">
            <option value=""></option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 组：
        </label>
        <div class="layui-input-inline">
          <select name="ddlTeam" lay-verify="required" lay-search="" id="ddlTeam" lay-filter="ddlTeam">
            <option value=""></option>
          </select>
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">
          <i class="layui-icon layui-icon-group"></i> 员工：
        </label>
        <div class="layui-input-inline">
          <select name="ddlEmployee" lay-verify="required" lay-search="" id="ddlEmployee" lay-filter="ddlEmployee">
            <option value=""></option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 发动机号：
        </label>
        <div class="layui-input-inline">
          <input id="txtEngineNo" type="text" name="txtEngineNo" class="layui-input" />
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 零件图号：
        </label>
        <div class="layui-input-inline">
          <input id="txtProductname" type="text" name="txtProductname" class="layui-input" />
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 机型：
        </label>
        <div class="layui-input-inline">
          <select name="ddlProductfamilyname" lay-verify="required" lay-search="" id="ddlProductfamilyname">
            <option value=""></option>
          </select>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 工时类型：
        </label>
        <div class="layui-input-inline">
          <select name="ddlType" lay-verify="required" id="ddlType">
            <option value="全部">全部</option>
            <option value="批产工时">批产工时</option>
            <option value="施工工时">施工工时</option>
            <option value="油封工时">油封工时</option>
            <option value="试车工时">试车工时</option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/过滤.png" height="14" alt="" /> 工时状态：
        </label>
        <div class="layui-input-inline">
          <select name="ddlStatus" lay-verify="required" id="ddlStatus">
            <option value="未处理">未处理</option>
            <option value="已核算">已核算</option>
            <option value="已核销">已核销</option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/日历.png" height="14" alt="" /> 检验日期：
        </label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" id="txtStartDate" />
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <img src="../images/日历.png" height="14" alt="" /> 至：
        </label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" id="txtStartEnd" />
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">
          <i class="layui-icon layui-icon-note"></i> 工时分值：
        </label>
        <div class="layui-input-inline">
          <input id="txtGSFZ" type="text" name="txtGSFZ" class="layui-input" value="" readonly />
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <i class="layui-icon layui-icon-note"></i> 汇总工时：
        </label>
        <div class="layui-input-inline">
          <input id="txtWorkTimeSum" type="text" name="txtWorktimeSum" class="layui-input" readonly />
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">
          <i class="layui-icon layui-icon-note"></i> 汇总绩效：
        </label>
        <div class="layui-input-inline">
          <input id="txtJxWorkTimeSum" type="text" name="txtJxWorkTimeSum" class="layui-input" readonly />
        </div>
      </div>
      <div class="layui-inline" style="margin-left: 60px;">
        <button type="button" class="layui-btn layui-btn-sm" id="btnSearch">
          <i class="layui-icon" style="font-weight: bold;">&#xe615;</i>查询
        </button>
        <button type="button" class="layui-btn layui-btn-sm" id="btnReset">
          <i class="layui-icon" style="font-weight: bold;">&#xe9aa;</i>重置
        </button>
        <button type="button" class="layui-btn layui-btn-sm" id="btnPrint">
          <i class="layui-icon" style="font-weight: bold;">&#xe66d;</i>导出
        </button>
      </div>
    </div>
    <div class="layui-fluid">
      <div class="layui-row">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-header">
              <img src="../images/工时.png" alt="" height="28" /> 员工工时统计
            </div>
            <div class="layui-card-body">
              <table class="layui-table" id="grid" lay-data="{text:{ none: '暂无相关数据'}}" lay-filter="grid">
                <thead>
                  <tr>
                    <th lay-data="{ width: 80 }">序号</th>
                    <th lay-data="{}">员工</th>
                    <th lay-data="{}">员工号</th>
                    <th lay-data="{}">个人工时</th>
                    <th lay-data="{}">个人绩效</th>
                    <th lay-data="{ fixed: 'right', title: '操作', width: 150, toolbar: '#barDemo'}">操作</th>
                  </tr>
                </thead>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
    <iframe id="iframe" src="" style="display: none;"></iframe>
    <script type="text/html" id="barDemo">
            <a class='layui-btn layui-btn-sm' lay-event='detail'>查看明细</a>
        </script>
  </form>
  <!-- 页眉区域 end-->
  <script type="text/javascript" src="../StaticFiles/layui/dist/layui.js"></script>
  <script type="text/javascript">
    $(function () {
      layui.use(['form', 'layer', 'table', 'laydate'], function () {
        var $ = layui.$;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table;
        var layer = layui.layer;
        var uid = layui.url().search.uid; //用户id
        var factoryid = layui.url().search.factoryid;
        var empInfo = null;
        var grid = null;

        // 页面右上方时钟
        function showTime() {
          var currentTime = new Date();
          var year = currentTime.getFullYear();
          var month = currentTime.getMonth() + 1;
          var date = currentTime.getDate();
          var day = currentTime.getDay();
          var hours = currentTime.getHours();
          var minutes = currentTime.getMinutes();
          var seconds = currentTime.getSeconds();
          var time = document.getElementById("currentTime");
          if (seconds < 10) {
            seconds = "0" + seconds;
          }
          if (minutes < 10) {
            minutes = "0" + minutes;
          }
          time.innerHTML = year + "年" + month + "月" + date + "日   " + hours + " : " + minutes + " : " + seconds;
        };
        setInterval(showTime, 500);

        //获取当天日期
        function GetCurrentDay() {
          var currentTime = new Date();
          var year = currentTime.getFullYear();
          var month = currentTime.getMonth() + 1;
          var date = currentTime.getDate();
          var day = currentTime.getDay();
          if (month < 10) {
            month = "0" + month;
          }
          return year + "-" + month + "-" + date;
        }

        //获取上月21日
        function getPreMonth(date) {
          var arr = date.split('-');
          var year = arr[0]; //获取当前日期的年份
          var month = arr[1]; //获取当前日期的月份
          var day = arr[2]; //获取当前日期的日
          if (day >= 21) {
            return year + '-' + month + '-21';
          }
          var days = new Date(year, month, 0);
          days = days.getDate(); //获取当前日期中月的天数
          var year2 = year;
          var month2 = parseInt(month) - 1;
          if (month2 == 0) {//如果是1月份，则取上一年的12月份
            year2 = parseInt(year2) - 1;
            month2 = 12;
          }
          var day2 = day;
          var days2 = new Date(year2, month2, 0);
          days2 = days2.getDate();
          if (day2 > days2) {//如果原来日期大于上一月的日期，则取当月的最大日期。比如3月的30日，在2月中没有30
            day2 = days2;
          }
          if (month2 < 10) {
            month2 = '0' + month2; //月份填补成2位。
          }
          var t2 = year2 + '-' + month2 + '-21';
          return t2;
        }

        var dataStart = laydate.render({
          elem: '#txtStartDate', //指定元素
          type: 'date',
          trigger: 'click',
          lang: 'cn',
          calendar: false, //公历重要节日
          theme: 'molv',
          range: false, //开启日期范围，默认使用“_”分割
          value: getPreMonth(GetCurrentDay())
        });

        var dataEnd = laydate.render({
          elem: '#txtStartEnd', //指定元素
          type: 'date',
          trigger: 'click',
          lang: 'cn',
          calendar: false, //公历重要节日
          theme: 'molv',
          range: false, //开启日期范围，默认使用“_”分割
          value: GetCurrentDay()
        });

        //查询机型并绑定
        $.ajax({
          type: "GET",
          url: "../handler/report/ZSWorktimeReport.ashx?type=GetProductFamily",
          dataType: "text",
          cashe: false,
          success: function (result) {
            var json = JSON.parse(result);
            for (var i = 0; i < json.length; i++) {
              $('#ddlProductfamilyname').append("<option value='" + json[i]["PRODUCTFAMILYNAME"] + "'>" + json[i]["PRODUCTFAMILYNAME"] + "</option>");
            }
            form.render("select");
          }
        });

        //查询工时分值
        $.ajax({
          type: "POST",
          url: "../handler/report/ZSWorktimeReport.ashx?type=GetGSFZ",
          dataType: "text",
          cashe: false,
          data: {
            factoryid: factoryid
          },
          success: function (result) {
            var json = JSON.parse(result);
            $("#txtGSFZ").val(json[0]["ATTRIBUTEVALUE"]);
          }
        });

        //查询用户信息
        $.ajax({
          type: "POST",
          url: "../handler/report/ZSWorktimeReport.ashx?type=GetEmpInfo",
          dataType: "text",
          cashe: false,
          data: {
            uid: uid
          },
          success: function (result) {
            var json = JSON.parse(result);
            if (json.length == 0) {
              alert("当前用户不存在，请重新登录");
              window.location.href = "http://" + window.location.host + "/Mesreport/login.aspx";
            } else {
              empInfo = json;
              BindFactory();
              BindDropDownControl();
            }
          }
        });

        function BindDropDownControl() {
          if (empInfo[0]["ROLENAME"] == "管理员") {
            var config = {
              factory: factoryid
            };
            BindWorkcenter(config);
            BindShift(config);
            BindTeam(config);
            BindEmp(config);

            //工区选择事件
            form.on('select(ddlWorkcenter)', function (data) {
              if (data.value == "") {
                return;
              }
              var config = {
                factory: factoryid,
                workcenterid: data.value
              };
              BindShift(config);
              BindTeam(config);
              BindEmp(config);
            });

            //班选择事件
            form.on('select(ddlShift)', function (data) {
              if (data.value == "") {
                return;
              }
              var config = {
                factory: factoryid,
                workcenterid: $("#ddlWorkcenter").val(),
                shiftid: data.value
              };
              BindTeam(config);
              BindEmp(config);
            });

            //组选择事件
            form.on('select(ddlTeam)', function (data) {
              if (data.value == "") {
                return;
              }
              var config = {
                factory: factoryid,
                workcenterid: $("#ddlWorkcenter").val(),
                shiftid: $("#ddlShift").val(),
                teamid: data.value
              };
              BindEmp(config);
            });
          }
          if (empInfo[0]["ROLENAME"] == "工区长") {
            var config = {
              factory: factoryid,
              workcenterid: empInfo[0]["WORKCENTERID"]
            };

            $('#ddlWorkcenter').append("<option value='" + empInfo[0]["WORKCENTERID"] + "'>" + empInfo[0]["WORKCENTERNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["WORKCENTERID"] + ']';
            $('#ddlWorkcenter').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlWorkcenter').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            BindShift(config); //绑定班
            BindTeam(config); //绑定组
            BindEmp(config); //绑定员工

            //班选择事件
            form.on('select(ddlShift)', function (data) {
              if (data.value == "") {
                return;
              }
              var config = {
                factory: factoryid,
                workcenterid: $("#ddlWorkcenter").val(),
                shiftid: data.value
              };
              BindTeam(config);
              BindEmp(config);
            });

            //组选择事件
            form.on('select(ddlTeam)', function (data) {
              if (data.value == "") {
                return;
              }
              var config = {
                factory: factoryid,
                workcenterid: $("#ddlWorkcenter").val(),
                shiftid: $("#ddlShift").val(),
                teamid: data.value
              };
              BindEmp(config);
            });
          }
          if (empInfo[0]["ROLENAME"] == "班长") {
            var config = {
              factory: factoryid,
              workcenterid: empInfo[0]["WORKCENTERID"],
              shiftid: empInfo[0]["SHIFTID"]
            };

            $('#ddlWorkcenter').append("<option value='" + empInfo[0]["WORKCENTERID"] + "'>" + empInfo[0]["WORKCENTERNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["WORKCENTERID"] + ']';
            $('#ddlWorkcenter').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlWorkcenter').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            $('#ddlShift').append("<option value='" + empInfo[0]["SHIFTID"] + "'>" + empInfo[0]["SHIFTNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["SHIFTID"] + ']';
            $('#ddlShift').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlShift').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            BindTeam(config);
            BindEmp(config);

            //组选择事件
            form.on('select(ddlTeam)', function (data) {
              if (data.value == "") {
                return;
              }
              var config = {
                factory: factoryid,
                workcenterid: $("#ddlWorkcenter").val(),
                shiftid: $("#ddlShift").val(),
                teamid: data.value
              };
              BindEmp(config);
            });
          }
          if (empInfo[0]["ROLENAME"] == "组长") {
            var config = {
              factory: factoryid,
              workcenterid: empInfo[0]["WORKCENTERID"],
              shiftid: empInfo[0]["SHIFTID"],
              teamid: empInfo[0]["TEAMID"]
            };

            $('#ddlWorkcenter').append("<option value='" + empInfo[0]["WORKCENTERID"] + "'>" + empInfo[0]["WORKCENTERNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["WORKCENTERID"] + ']';
            $('#ddlWorkcenter').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlWorkcenter').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            $('#ddlShift').append("<option value='" + empInfo[0]["SHIFTID"] + "'>" + empInfo[0]["SHIFTNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["SHIFTID"] + ']';
            $('#ddlShift').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlShift').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            $('#ddlTeam').append("<option value='" + empInfo[0]["TEAMID"] + "'>" + empInfo[0]["TEAMNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["TEAMID"] + ']';
            $('#ddlTeam').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlTeam').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            BindEmp(config);
          }
          if (empInfo[0]["ROLENAME"] == "工人") {
            $('#ddlWorkcenter').append("<option value='" + empInfo[0]["WORKCENTERID"] + "'>" + empInfo[0]["WORKCENTERNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["WORKCENTERID"] + ']';
            $('#ddlWorkcenter').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlWorkcenter').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            $('#ddlShift').append("<option value='" + empInfo[0]["SHIFTID"] + "'>" + empInfo[0]["SHIFTNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["SHIFTID"] + ']';
            $('#ddlShift').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlShift').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            $('#ddlTeam').append("<option value='" + empInfo[0]["TEAMID"] + "'>" + empInfo[0]["TEAMNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["TEAMID"] + ']';
            $('#ddlTeam').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlTeam').eq(0).attr({ "disabled": "disabled" });
            form.render("select");

            $('#ddlEmployee').append("<option value='" + empInfo[0]["EMPLOYEEID"] + "'>" + empInfo[0]["FULLNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["EMPLOYEEID"] + ']';
            $('#ddlEmployee').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlEmployee').eq(0).attr({ "disabled": "disabled" });
            form.render("select");
          }
        };

        //绑定分厂
        function BindFactory() {
          $.ajax({
            type: "POST",
            url: "../handler/report/ZSWorktimeReport.ashx?type=GetFactory",
            dataType: "text",
            cashe: false,
            data: {
              factoryid: layui.url().search.factoryid
            },
            success: function (result) {
              var data = JSON.parse(result);
              if (data.length > 0) {
                $('#ddlFactory').append("<option value='" + data[0]["FACTORYID"] + "'>" + data[0]["FACTORYNAME"] + "</option>");
              }
              form.render("select");
              var select = 'dd[lay-value=' + data[0]["FACTORYID"] + ']';
              $('#ddlFactory').siblings("div.layui-form-select").find('dl').find(select).click();
              $('#ddlFactory').eq(0).attr({ "disabled": "disabled" });
              form.render("select");
            }
          });
        };

        //绑定工区
        function BindWorkcenter(config) {
          var config = config;
          if (empInfo[0]["ROLENAME"] === "工区长") {
            $('#ddlWorkcenter').append("<option value='" + empInfo[0]["WORKCENTERID"] + "'>" + empInfo[0]["WORKCENTERNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["WORKCENTERID"] + ']';
            $('#ddlWorkcenter').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlWorkcenter').eq(0).attr({ "disabled": "disabled" });
            form.render("select");
          } else {
            $.ajax({
              type: "POST",
              url: "../handler/report/ZSWorktimeReport.ashx?type=GetWorkcenter",
              dataType: "text",
              cashe: false,
              data: {
                factoryid: factoryid
              },
              success: function (result) {
                var data = JSON.parse(result);
                for (var i = 0; i < data.length; i++) {
                  $('#ddlWorkcenter').append("<option value='" + data[i]["WORKCENTERID"] + "'>" + data[i]["WORKCENTERNAME"] + "</option>");
                }
                form.render("select");
              }
            });
          }
        };

        //绑定班（Shift）
        function BindShift(config) {
          var config = config;
          if (empInfo[0]["ROLENAME"] === "班长") {
            $('#ddlShift').append("<option value='" + empInfo[0]["SHIFTID"] + "'>" + empInfo[0]["SHIFTNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["SHIFTID"] + ']';
            $('#ddlShift').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlShift').eq(0).attr({ "disabled": "disabled" });
            form.render("select");
          } else {
            $.ajax({
              type: "POST",
              url: "../handler/report/ZSWorktimeReport.ashx?type=GetShift",
              dataType: "text",
              cashe: false,
              data: {
                factoryid: factoryid,
                workcenterid: config.workcenterid
              },
              success: function (result) {
                var data = JSON.parse(result);

                $('#ddlShift').empty();
                $('#ddlShift').append("<option value=''></option>");
                form.render("select");

                for (var i = 0; i < data.length; i++) {
                  $('#ddlShift').append("<option value='" + data[i]["SHIFTID"] + "'>" + data[i]["SHIFTNAME"] + "</option>");
                }
                form.render("select");
              }
            });
          }
        };

        //查询组（Team）
        function BindTeam(config) {
          var config = config;
          if (empInfo[0]["ROLENAME"] === "组长") {
            $('#ddlTeam').append("<option value='" + empInfo[0]["TEAMID"] + "'>" + empInfo[0]["TEAMNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["TEAMID"] + ']';
            $('#ddlTeam').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlTeam').eq(0).attr({ "disabled": "disabled" });
            form.render("select");
          } else {
            $.ajax({
              type: "POST",
              url: "../handler/report/ZSWorktimeReport.ashx?type=GetTeam",
              dataType: "text",
              cashe: false,
              data: {
                factoryid: factoryid,
                workcenterid: config.workcenterid,
                shiftid: config.shiftid
              },
              success: function (result) {
                var data = JSON.parse(result);

                $('#ddlTeam').empty();
                $('#ddlTeam').append("<option value=''></option>");
                form.render("select");

                for (var i = 0; i < data.length; i++) {
                  $('#ddlTeam').append("<option value='" + data[i]["TEAMID"] + "'>" + data[i]["TEAMNAME"] + "</option>");
                }
                form.render("select");
              }
            });
          }
        };

        //查询员工
        function BindEmp(config) {
          var config = config;
          if (empInfo[0]["ROLENAME"] === "工人") {
            $('#ddlEmployee').append("<option value='" + empInfo[0]["EMPLOYEEID"] + "'>" + empInfo[0]["FULLNAME"] + "</option>");
            form.render("select");
            var select = 'dd[lay-value=' + empInfo[0]["EMPLOYEEID"] + ']';
            $('#ddlEmployee').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#ddlEmployee').eq(0).attr({ "disabled": "disabled" });
            form.render("select");
          } else {
            $.ajax({
              type: "POST",
              url: "../handler/report/ZSWorktimeReport.ashx?type=GetEmp",
              dataType: "text",
              cashe: false,
              data: {
                factoryid: factoryid,
                workcenterid: config.workcenterid,
                shiftid: config.shiftid,
                teamid: config.teamid
              },
              success: function (result) {
                var data = JSON.parse(result);

                $('#ddlEmployee').empty();
                $('#ddlEmployee').append("<option value=''></option>");
                form.render("select");

                for (var i = 0; i < data.length; i++) {
                  $('#ddlEmployee').append("<option value='" + data[i]["EMPLOYEEID"] + "'>" + data[i]["FULLNAME"] + "</option>");
                }
                form.render("select");
              }
            });
          }
        };

        //弹出层通用方法
        function openDialog(config) {
          layer.open({
            title: config.title,
            type: 1,
            content: "<table class='layui-hide' id='test'></table>",
            area: ['98%', '98%'],
            skin: 'layui-layer-rim',
            success: function (layero) {
              table.render({
                elem: '#test',
                url: config.url,
                method: 'POST',
                cols: config.cols,
                where: config.QueryString,
                request: {
                  pageName: 'page', //页码的参数名称，默认：page
                  limitName: 'rows' //每页数据量的参数名，默认：limit
                },
                cellMinWidth: 80,
                page: {
                  theme: '#009688'
                },
                text: {
                  none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                },
                done: function (res, curr, count) {
                  var that = this.elem.next();
                  res.data.forEach(function (item, index) {
                    if (index % 2 !== 0) {
                      var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css({ "background": "#eee" });
                    }
                  });
                }
              });
            }
          });
        };

        function GetQueryObjec() {
          var factoryid = layui.url().search.factoryid;
          var workcenterid = $("#ddlWorkcenter").val() === "" ? "空" : $("#ddlWorkcenter").val();
          var shiftid = $("#ddlShift").val() === "" ? "空" : $("#ddlShift").val();
          var teamid = $("#ddlTeam").val() === "" ? "空" : $("#ddlTeam").val();
          var employeeid = $("#ddlEmployee").val() === "" ? "空" : $("#ddlEmployee").val();
          var engineno = $("#txtEngineNo").val() === "" ? "空" : $("#txtEngineNo").val();
          var productname = $("#txtProductname").val() === "" ? "空" : $("#txtProductname").val();
          var productfamilyname = $("#ddlProductfamilyname").val() === "" ? "空" : $("#ddlProductfamilyname").val();
          var startDate = $("#txtStartDate").val() === "" ? "空" : $("#txtStartDate").val();
          var endDate = $("#txtStartEnd").val() === "" ? "空" : $("#txtStartEnd").val();
          var ddlType = $("#ddlType").val();
          var gsfz = $("#txtGSFZ").val() === "" ? "1" : $("#txtGSFZ").val(); //工时分值
          var status = $("#ddlStatus").val(); //工时状态

          return {
            factoryid: factoryid,
            workcenterid: workcenterid,
            shiftid: shiftid,
            teamid: teamid,
            employeeid: employeeid,
            engineno: engineno,
            productname: productname,
            productfamilyname: productfamilyname,
            startDate: startDate,
            endDate: endDate,
            ddlType: ddlType,
            gsfz: gsfz,
            status: status
          };
        };

        //查询按钮
        $("#btnSearch").click(function () {
          if ($("#txtStartDate").val() === "") {
            layer.alert("起始时间不能为空！", { icon: 2, title: '提示' });
            return;
          }
          if ($("#txtStartEnd").val() === "") {
            layer.alert("截止时间不能为空！", { icon: 2, title: '提示' });
            return;
          }

          var index = layer.load(0, { shade: [0.2, '#000'], time: 1000 * 1000 });

          grid = table.render({
            elem: '#grid'
            , url: "../handler/report/ZSWorktimeReport.ashx?type=GetWorkTime"
            , method: 'POST'
            , cols: [[
              { type: 'numbers', title: '序号', width: 80 }
              , { field: 'FULLNAME', title: '员工' }
              , { field: 'EMPLOYEENAME', title: '员工号' }
              , { field: 'employeeworktime', title: '个人工时' }
              , { field: 'TotalJX', title: '个人绩效' }
              , { fixed: 'right', title: '操作', width: 150, toolbar: '#barDemo' } //这里的toolbar值是模板元素的选择器
            ]]
            , where: GetQueryObjec()
            , text: {
              none: '暂无相关数据'
            }
            , done: function (res, curr, count) {
              $("#txtWorkTimeSum").val(res.totalGS);
              $("#txtJxWorkTimeSum").val(res.totalJXGS);
              layer.close(index);
              var that = this.elem.next();
              res.data.forEach(function (item, index) {
                if (index % 2 !== 0) {
                  var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css({ "background": "#eee" });
                }
              });
            }
          });

          table.on('tool(grid)', function (obj) { //注：tool 是工具条事件名，grid是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'detail') {
              var ddlType = $("#ddlType").val();
              if (ddlType == "全部") {
                layer.alert("类型为【全部】时，不能查看明细，请选择其他类型，点击【查询】后再试！", { icon: 2, title: '提示' });
                table.reload('grid', { url: '', data: [] });
                $("#txtWorkTimeSum").val("0");
                $("#txtJxWorkTimeSum").val("0");
                return;
              }
              var config = {};
              config.QueryString = GetQueryObjec();
              config.QueryString.employeeid = obj.data.EMPLOYEEID;
              config.url = "../handler/report/ZSWorktimeReport.ashx?type=GetWorkTimeDetails";
              config.title = "<i class='layui-icon layui-icon-group'></i>：" + obj.data.FULLNAME
                + "【" + ddlType + "】"
                + "明细 <i class='layui-icon layui-icon-log'></i>：";
              if (ddlType === "批产工时") {
                config.cols = [[
                  { type: 'numbers' }
                  , { field: 'CONTAINERNO', title: '任务单' }
                  , { field: 'WORKFLOWNAME', title: '工艺名称' }
                  , { field: 'WORKFLOWDESC', title: '工艺描述' }
                  , { field: 'CHECKTYPE', title: '初检装' }
                  , { field: 'SPECNAME', title: '工序' }
                  , { field: 'STEPINFODESC', title: '工步' }
                  , { field: 'WORKCENTERNAME', title: '工区' }
                  , {
                    field: 'REPORTTIME', title: '报工时间',
                    templet: function (d) {
                      if (d.REPORTTIME === null) {
                        return "";
                      } else {
                        return d.REPORTTIME.replace('T', ' ');
                      }
                    }
                  }
                  , {
                    field: 'CHECKDATE', title: '检验日期',
                    templet: function (d) {
                      if (d.CHECKDATE === null) {
                        return "";
                      } else {
                        return d.CHECKDATE.replace('T', ' ');
                      }
                    }
                  }
                  , { field: 'DURATIONPERUNIT', title: '单位工时' }
                  , { field: 'EMPLOYEEWORKTIME', title: '合计工时' }
                ]];
              } else if (ddlType === "施工工时") {
                config.cols = [[
                  { type: 'numbers' }
                  , { field: 'CONTAINERNO', title: '任务单' }
                  , { field: 'SPECNAME', title: '工序' }
                  , { field: 'WSDESCRIPTION', title: '内容描述' }
                  , { field: 'WORKFLOWNAME', title: '工艺名称' }
                  , { field: 'WORKFLOWDESC', title: '工艺描述' }
                  , { field: 'STEPINFODESC', title: '工步' }
                  , { field: 'WORKCENTERNAME', title: '工区' }
                  , {
                    field: 'REPORTTIME', title: '报工时间',
                    templet: function (d) {
                      if (d.REPORTTIME === null) {
                        return "";
                      } else {
                        return d.REPORTTIME.replace('T', ' ');
                      }
                    }
                  }
                  , {
                    field: 'CHECKDATE', title: '检验日期',
                    templet: function (d) {
                      if (d.CHECKDATE === null) {
                        return "";
                      } else {
                        return d.CHECKDATE.replace('T', ' ');
                      }
                    }
                  }
                  , { field: 'DURATIONPERUNIT', title: '单位工时' }
                  , { field: 'EMPLOYEEWORKTIME', title: '合计工时' }
                ]];
              } else {
                config.cols = [[
                  { type: 'numbers' }
                  , { field: 'CONTAINERNO', title: '任务单' }
                  , { field: 'SPECNAME', title: '工序' }
                  , { field: 'STEPINFODESC', title: '工步' }
                  , { field: 'WORKCENTERNAME', title: '工区' }
                  , {
                    field: 'REPORTTIME', title: '报工时间',
                    templet: function (d) {
                      if (d.REPORTTIME === null) {
                        return "";
                      } else {
                        return d.REPORTTIME.replace('T', ' ');
                      }
                    }
                  }
                  , {
                    field: 'CHECKDATE', title: '检验日期',
                    templet: function (d) {
                      if (d.CHECKDATE === null) {
                        return "";
                      } else {
                        return d.CHECKDATE.replace('T', ' ');
                      }
                    }
                  }
                  , { field: 'DURATIONPERUNIT', title: '单位工时' }
                  , { field: 'EMPLOYEEWORKTIME', title: '合计工时' }
                ]];
              }
              openDialog(config);
            }
          });
        });

        //重置按钮
        $("#btnReset").click(function () {
          table.reload('grid', { url: '', data: [] });
          $("#txtWorkTimeSum").val("0");
          $("#txtJxWorkTimeSum").val("0");
          $("#txtEngineNo").val("");
          $("#txtProductname").val("");
        });

        //导出按钮
        $("#btnPrint").click(function (e) {
          e.preventDefault();

          if ($("#txtStartDate").val() === "") {
            layer.alert("起始时间不能为空！", { icon: 2, title: '提示' });
            return;
          }
          if ($("#txtStartEnd").val() === "") {
            layer.alert("截止时间不能为空！", { icon: 2, title: '提示' });
            return;
          }

          var factoryid = layui.url().search.factoryid;
          var workcenterid = $("#ddlWorkcenter").val() === "" ? "空" : $("#ddlWorkcenter").val();
          var shiftid = $("#ddlShift").val() === "" ? "空" : $("#ddlShift").val();
          var teamid = $("#ddlTeam").val() === "" ? "空" : $("#ddlTeam").val();
          var employeeid = $("#ddlEmployee").val() === "" ? "空" : $("#ddlEmployee").val();
          var engineno = $("#txtEngineNo").val() === "" ? "空" : $("#txtEngineNo").val();
          var productname = $("#txtProductname").val() === "" ? "空" : $("#txtProductname").val();
          var productfamilyname = $("#ddlProductfamilyname").val() === "" ? "空" : $("#ddlProductfamilyname").val();
          var startDate = $("#txtStartDate").val() === "" ? "空" : $("#txtStartDate").val();
          var endDate = $("#txtStartEnd").val() === "" ? "空" : $("#txtStartEnd").val();
          var ddlType = $("#ddlType").val();
          var gsfz = $("#txtGSFZ").val() === "" ? "1" : $("#txtGSFZ").val(); //工时分值
          var status = $("#ddlStatus").val(); //工时状态

          var QueryString = GetQueryObjec();

          var index = layer.load(0, { shade: [0.5, '#000'] });
          var url = '../handler/report/ZSWorktimeReport.ashx?type=print' + "&" + $.param(QueryString)
          $.fileDownload(url, {
            httpMethod: 'POST',
            successCallback: function (url) {
              layer.alert("导出成功", { icon: 1, title: '提示' });
              layer.close(index);
            },
            failCallback: function (url) {
              layer.close(index);
              layer.alert("未查询到数据，不能导出", { icon: 2, title: '提示' });
            }
          })
        });

      });
    });
  </script>
</body>

</html>